package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.app.po.VideoRedEnvelopesConfig;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

public interface VideoRedEnvelopesConfigMapper extends BaseMapper<VideoRedEnvelopesConfig> {


    @Select("select * from video_red_envelopes_config where  effective_start_time <= now()  and now() <= effective_end_time")
    VideoRedEnvelopesConfig selectOneByEffectiveTime();

    @Select("select * from video_red_envelopes_config where  (effective_start_time <= #{startDateTime}  and #{startDateTime} <= effective_end_time ) or (effective_start_time <= #{endDateTime}  and #{endDateTime} <= effective_end_time )")
    List<VideoRedEnvelopesConfig> selectTimeConflict(@Param("startDateTime") LocalDateTime startDateTime,@Param("endDateTime") LocalDateTime endDateTime);

    @Select("select * from video_red_envelopes_config where id != #{id} and ((effective_start_time <= #{startDateTime}  and #{startDateTime} <= effective_end_time ) or (effective_start_time <= #{endDateTime}  and #{endDateTime} <= effective_end_time ))")
    List<VideoRedEnvelopesConfig> selectTimeConflictAndFilterId(@Param("id") Integer id ,@Param("startDateTime") LocalDateTime startDateTime,@Param("endDateTime") LocalDateTime endDateTime);
}
